﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
   public class BuyerFixedPricePeriodItem
    {

       /// <summary>
       /// 根据周价订单企业ID得到该企业该日期范围内的产品大类ID
       /// </summary>
       /// <param name="companyId"></param>
       /// <returns></returns>
        public static DataTable rootCategorylistWithCompanyId(int companyId)
        {
            return DbHelper.ExecuteDataTable("[dbo].[P_BuyerFixedPricePeriodItem_RootCategory_listwithByCompanyId]", companyId);
        }

       /// <summary>
        /// 根据周价订单企业ID和大类ID得到该企业该日期范围内的产品小类ID
       /// </summary>
       /// <param name="companyId"></param>
       /// <param name="category"></param>
       /// <returns></returns>
        public static DataTable subCategorylistWithCompanyId(int companyId, int category)
        {
            return DbHelper.ExecuteDataTable("[dbo].[P_BuyerFixedPricePeriodItem_SubCategory_listwithByCompanyId]", companyId, category);
        }

        public static DataTable listWithCategoryAndCompany(int companyId, int categoryid)
        {
            return DbHelper.ExecuteDataTable("[dbo].[P_BuyerFixedPricePeriodItem_listwithByCompanyIdAndCategoryId]", companyId, categoryid);
        }
        public static int insert(BuyerFixedPricePeriodItemEntity _bfpEnt)
        {
            return Convert.ToInt32(DbHelper.ExecuteScalar("p_BuyerFixedPricePeriodItem_insert", _bfpEnt.Fpid,_bfpEnt.ProductId,_bfpEnt.SellerId,_bfpEnt.SellerPrice,_bfpEnt.Price,_bfpEnt.AdminId));
        }

        public static DataTable HistoryPrice_subCategorylistWithCompanyId(int companyId, int category)
        {
            return DbHelper.ExecuteDataTable("[dbo].[P_BuyerFixedPricePeriodItem_SubCategory_listwithByCompanyId]", companyId, category);
        }

        public static DataTable HistoryPrice_rootCategorylistWithCompanyId(int companyId)
        {
            return DbHelper.ExecuteDataTable("[dbo].[P_BuyerFixedPricePeriodItem_RootCategory_listwithByCompanyId]", companyId);
        }

        public static DataTable HistoryPrice_listWithCategoryAndCompany(int companyId, int categoryid)
        {
            return DbHelper.ExecuteDataTable("[dbo].[P_BuyerFixedPricePeriodItem_listwithByCompanyIdAndCategoryId]", companyId, categoryid);
        }
        public static DataTable listByBuyerIdAndReceiveDt(int buyerId, DateTime receiveDt)
        {
            return DbHelper.ExecuteDataTable("[dbo].[p_BuyerFixedPricePeriodItem_listByBuyerIdAndReceiveDt]", buyerId, receiveDt);
        }
        public static BuyerFixedPricePeriodItemEntity getBybpId(int bpId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("[dbo].[p_buyerFixedPricePeriodItem_getByBpId]", bpId);
            BuyerFixedPricePeriodItemEntity bpEnt = new BuyerFixedPricePeriodItemEntity();
            if (dr != null)
            {
                bpEnt.Fpid = Convert.ToInt32(dr["fpid"]);
                bpEnt.ProductId = Convert.ToInt32(dr["productId"]);
                bpEnt.SellerId = Convert.ToInt32(dr["sellerId"]);
                bpEnt.SellerPrice = Convert.ToDecimal(dr["sellerPrice"]);
                bpEnt.Price = Convert.ToDecimal(dr["price"]);
                bpEnt.InputDt = Convert.ToDateTime(dr["inputDt"]);
                bpEnt.AdminId = Convert.ToInt32(dr["adminId"]);
            }
            return bpEnt;
        }
    }
}
